#pragma once

#include <string>
#include <iostream>
#include <fstream>
#include <bitset>

#include "DataStream.h"
#include "OpenMode.h"

namespace Huffman {

	class FileDataStream : public DataStream
	{
	public:
		FileDataStream(std::string filePath, OpenMode openMode);
		FileDataStream(std::string filePath, OpenMode openMode, int buferSize);
		~FileDataStream(void);

		virtual char read();
		virtual bool readBit();
		virtual void write(char data);
		virtual void writeEncodedSymbol(EncodedSymbol* symbol);
		virtual void writeBit(bool bit);
		virtual void close();

		virtual void flush();
		virtual bool isEof();		

		virtual std::string getPath();

	private:
		void readBuffer();
		void writeBuffer();

		std::string filePath;
		std::fstream* stream;
		static const int BufferSize = 8;
		std::bitset<8> buffer;
		int bufferIndex;		
	};
}

